;
; utilities to work with types
;
;
;





;
; converts given symbol type to its string equivalent
;
(defun symbol-type-to-string (sym-type)
  (let ((type-info (get-type-info sym-type)))
    (type-info-lang-name type-info)
    ))

(defun list-type-to-string (complex-type)
  (assert (and (listp complex-type) (= (length complex-type) 2)))
  (let ((type-modifier (first complex-type)))
    (cond
     ((eq type-modifier 'ptr) (concatenate 'string
                                           (stringify-typename (second complex-type))
                                           " " ; delimeter
                                           "*" ; pointer specifier
                                           ))
     ((eq type-modifier 'const) (concatenate 'string
                                             "const" ; const specifier
                                             " " ; delimeter
                                             (stringify-typename (second complex-type))
                                             ))
     (t (error (format nil "unknown type modifier: ~a" type-modifier)))
     )))

(defun stringify-typename (typename)
  (if (symbolp typename)
      (symbol-type-to-string typename)
    (list-type-to-string typename)
    ))

(defun stringify-symbol-name (sym-name)
  (assert (symbolp sym-name))
  (format nil "~(~a~)" sym-name) ; make lowercase
  )

;
; stringifies arguments list
;
(defun stringify-arg-list (args)
  (let ((result "(") (is-first t))
    (dolist (arg args)
      (let (
            (type-decl (stringify-typename (first arg))) ; type decl in the args list
            (arg-name (stringify-symbol-name (second arg))) ; arg name itself
            )
        (if is-first
            (setf is-first nil)
          (setf result (concatenate 'string result ","))
          )
        (setf result (concatenate 'string
                                  result
                                  (format nil " ~a ~a" type-decl arg-name)))
        ))
    (concatenate 'string result (if is-first ")" " )"))))
